import socketserver,time
__auther__='zhuifeng'
buffer_size = 1024
ADDR = ("localhost", 1234)
class Myserver(socketserver.BaseRequestHandler):#  或者socketserver.StreamRequestHandler
    def handle(self):
        try:
            print('已经连接:', self.client_address) # addr
            print("conn", self.request)  # conn
            while True:
                data = self.request.recv(buffer_size)
                if not data:break
                print(time.ctime(),"收到客户端%s发送的消息是%s," %(self.client_address,data))
                self.request.sendall(data.upper())
        except Exception:
            print(Exception)
if __name__ == '__main__':
    tcpServ = socketserver.ThreadingTCPServer(ADDR, Myserver)
    # tcpServ = socketserver.ForkingTCPServer(ADDR, Myserver)  # 多进程Windows下不可以
    print(tcpServ.server_address)
    print(tcpServ.RequestHandlerClass)
    print('等待新的连接。。。。')
    tcpServ.serve_forever()